package com.oddfar.campus.business.controller.admin;

import com.oddfar.campus.business.domain.entity.SensitiveEntity;
import com.oddfar.campus.business.service.SensitiveService;
import com.oddfar.campus.common.annotation.ApiResource;
import com.oddfar.campus.common.domain.PageResult;
import com.oddfar.campus.common.domain.R;
import com.oddfar.campus.common.enums.ResBizTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * @Description
 * @Author Zhou CityEast
 * @Date 2024/11/19 上午 10:29
 **/
@RestController
@RequestMapping("/admin/sensitive")
@ApiResource(name = "敏感词管理" , appCode = "campus" , resBizType = ResBizTypeEnum.BUSINESS)
public class SensitiveController {
    @Autowired
    private SensitiveService sensitiveService;

    /**
     * 查询敏感词列表
     */
    @PreAuthorize("@ss.resourceAuth()")
    @GetMapping("/list")
    public R list(SensitiveEntity sensitive) {
        PageResult<SensitiveEntity> page = sensitiveService.page(sensitive);

        return R.ok().put(page);
    }


    /**
     * 获取敏感词详细信息
     */
    @PreAuthorize("@ss.resourceAuth()")
    @GetMapping(value = "/{sensitiveId}")
    public R getInfo(@PathVariable("sensitiveId") Long sensitiveId) {
        return R.ok(sensitiveService.getById(sensitiveId));
    }

    /**
     * 新增敏感词
     */
    @PreAuthorize("@ss.resourceAuth()")
    @PostMapping
    public R add(@Validated @RequestBody SensitiveEntity sensitive) {
        return R.ok(sensitiveService.insertSensitive(sensitive));
    }

    /**
     * 修改敏感词
     */
    @PreAuthorize("@ss.resourceAuth()")
    @PutMapping
    public R edit(@Validated @RequestBody SensitiveEntity sensitive) {
        return R.ok(sensitiveService.updateSensitive(sensitive));
    }

    /**
     * 删除敏感词
     */
    @PreAuthorize("@ss.resourceAuth()")
    @DeleteMapping("/{sensitiveIds}")
    public R remove(@PathVariable Long[] sensitiveIds) {
        return R.ok(sensitiveService.removeBatchByIds((Arrays.asList(sensitiveIds))));
    }


}
